package com.example.myapplication.navigation.fragment;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.myapplication.R;

public abstract class BaseLifeFragment extends Fragment {

    String logTag="";

    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        logTag= initLogHead();
        log(logTag+"onAttach(Context context)");
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        log(logTag+"onCreate(Bundle savedInstanceState)");

    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        log(logTag+"onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState)");
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        log(logTag+"onViewCreated(View view, Bundle savedInstanceState)");
    }

    @Override
    public void onStart() {
        super.onStart();
        log(logTag+"onStart()");
    }

    @Override
    public void onResume() {
        super.onResume();
        log(logTag+"onResume()");
    }

    @Override
    public void onPause() {
        super.onPause();
        log(logTag+"onPause()");
    }

    @Override
    public void onStop() {
        super.onStop();
        log(logTag+"onStop()");
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        log(logTag+"onDestroyView()");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        log(logTag+"onDestroy()");
    }

    @Override
    public void onDetach() {
        super.onDetach();
        log(logTag+"onDetach()");
    }

    public abstract String initLogHead();

    public void log(String msg){
        Log.e(getLogTag(),msg);
    }

    public String getLogTag(){
        return "fragment_lifecycle";
    }
}
